<?php

namespace App\Admin\Extensions;

use Encore\Admin\Grid\Exporters\AbstractExporter;
use Maatwebsite\Excel\Facades\Excel;

class ExcelExpoter extends AbstractExporter
{
    public function export()
    {
        Excel::create('权益兑奖', function($excel) {

            $excel->sheet('Sheetname', function($sheet) {
                // 这段逻辑是从表格数据中取出需要导出的字段
                $rows = collect($this->getData())->map(function ($item) {
                    return array_only($item, [
                        'performance_branch',
                        'host_branch',
                        'host_mechanism_number',
                        'host_mechanism_name',
                        'host_account_manager_number',
                        'host_account_manager_name',
                        'co_sponsor_account_manager',
                        'is_satisfy_satisfy',
                        'proportion_of_customers',
                        'customer_number',
                        'customer_name',
                        'company_business_credit_customers',
                        'customer_account_opening_date',
                        'cost_customer',
                        'cost_customer_grading',
                        'not_valuable',
                        'active_period_company',
                        'name',
                        'phone',
                        'address'
                    ]);
                });

                $sheet->rows($rows);

            });

        })->export('xls');
    }
}